package com.tedu.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description 全局异常捕捉通知
 * @Author dangxianyue
 * @Date 2024/5/7 15:06
 */
@ControllerAdvice
public class GlobalExceptionAdvice {

    // 获取Logger实例
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionAdvice.class);

    // 暂时把所有的异常都这样抛，实际上业务异常要另外的逻辑
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public String handleException(Exception e) {
        logger.error("发生异常：", e);
        return "SERVER ERROR";
    }
}
